package practice;

/**
 * Description:
 *
 * @Author cowen
 * @Create 2023/10/19 11:00
 * @Version 1.0
 */
class ArrayBinarySearch{
    public static void main(String[] args) {
        int[] nums = {11,22,33,44,55,66,77,88,99};
        int target =55;
        // 首索引  尾索引
        int head =0;
        int end = nums.length-1;
        while (head<=end){
            int middle = (head+end) / 2;
            if(target==nums[middle]){
                System.out.println("找到了："+target+" 位置为："+middle);
                break;
            }else if(target>nums[middle]){
                head=middle+1;
            }else{
                end=middle-1;
            }
        }
    }
}
